package Servlet;

import bean.Message;
import net.sf.json.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "RequestNew", value = "/RequestNew")
public class RequestNew extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String id = request.getParameter("id");
//        Cookie[] cookies = request.getCookies();
        PrintWriter out = response.getWriter();

        HttpSession session = request.getSession();
        Message message = (Message) session.getAttribute("newMessage");
        String NO = "NO";
        Map map = new HashMap<String,String>();
        map.put(NO,NO);
        System.out.println(id );
        if(message.getToId().equals(id)) {
            System.out.println(message.getToId());
            out.print(JSONObject.fromObject(message));
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
